//
//  XJCVideoPlayViewController.m
//  On The Load
//
//  Created by 许嘉成 on 15/11/11.
//  Copyright © 2015年 @@叶一闽. All rights reserved.
//

#import "XJCVideoPlayViewController.h"
#import <AVFoundation/AVFoundation.h>
#import "XJCVideoModel.h"

@interface XJCVideoPlayViewController ()<UITableViewDataSource,UITableViewDelegate>
//声明一个属性(无setter,getter方法)
{
    NSDateFormatter *_dateFormatter;
}

/**播放器对象**/
@property (nonatomic, strong) AVPlayer *player;

/**播放器容器**/
@property (nonatomic, strong) UIView *container;

/**播放/暂停按钮**/
@property (nonatomic, strong) UIButton *playOrPause;

/**显示播放时间**/
@property (nonatomic, strong) UILabel *timeLabel;

/**滑块儿**/
@property (nonatomic, strong) UISlider *slider;

/**进度条**/
@property (nonatomic, strong) UISlider *bgSlider;

/**顶部视图**/
@property (nonatomic ,strong) UIView *topView;

/**底部视图**/
@property (nonatomic ,strong) UIView *bottomView;

/**标题框**/
@property (nonatomic, strong) UILabel *titleLabel;

/**返回按钮**/
@property (nonatomic, strong) UIButton *backBtn;

/**选集按钮**/
@property (nonatomic, strong) UIButton *selectedBtn;

/**提示框**/
@property (nonatomic, strong) UILabel  *messageBox;

/**是否正在操作**/
@property (nonatomic, assign) BOOL isOperation;

/**隐藏计数**/
@property (nonatomic, assign) NSInteger hiddenCount;

/**选集tableview**/
@property (nonatomic, strong) UITableView *selectedTableView;

/**AV返回值**/
@property (nonatomic, strong) id playBackObserver;

/**清晰度按钮**/
@property (nonatomic, strong) UIButton *typeBtn;

/**清晰度视图**/
@property (nonatomic, strong) UIView *typeView;

@property (nonatomic, assign) BOOL isPause;

@end

@implementation XJCVideoPlayViewController

#pragma mark 视图初始化
/****视图初始化****/
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor blackColor];
    self.hiddenCount = 0;
    self.isOperation = NO;
    self.isPause = NO;

    self.messageBox = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100*SCALEH, 40*SCALEW)];
    self.messageBox.center = CGPointMake(HEIGHT/2, WIDTH/2);
    self.messageBox.layer.masksToBounds = YES;
    self.messageBox.layer.cornerRadius = 10*SCALEH;
    self.messageBox.textColor = [UIColor whiteColor];
    self.messageBox.textAlignment = NSTextAlignmentCenter;
    self.messageBox.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
    [self.view addSubview:self.messageBox];
    
    [self createSubviews];
    [_player play];
    [self userEnable];
}

//创建子视图
- (void)createSubviews{
    self.container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, HEIGHT, WIDTH)];
    [self.view addSubview:_container];
    
    [self setupSubviews];
    
    self.bottomView = [[UIView alloc]initWithFrame:CGRectMake(0,315*SCALEW , HEIGHT, 60*SCALEW)];
    self.bottomView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
    [self.view addSubview:_bottomView];
    
    self.playOrPause = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.playOrPause setImage:[UIImage imageNamed:@"pause@2x"] forState:UIControlStateNormal];
    self.playOrPause.frame = CGRectMake(5*SCALEW, 5*SCALEW, 50*SCALEW, 50*SCALEW);
    
    [self.playOrPause addTarget:self action:@selector(playOrPauseAction) forControlEvents:UIControlEventTouchUpInside];
    [self.bottomView addSubview:_playOrPause];
    
    self.timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(55*SCALEH, 20*SCALEW, 120*SCALEH, 20*SCALEW)];
    self.timeLabel.font = [UIFont systemFontOfSize:12.5];
    self.timeLabel.textColor = [UIColor whiteColor];
    self.timeLabel.textAlignment = NSTextAlignmentCenter;
    self.timeLabel.text = @"00:00/00:00";
    [self.bottomView addSubview:_timeLabel];
    
    self.bgSlider = [[UISlider alloc] initWithFrame:CGRectMake(180*SCALEH, 20*SCALEW, 460 * SCALEH,  20 * SCALEW)];
    self.bgSlider.thumbTintColor = [UIColor clearColor];
    self.bgSlider.minimumTrackTintColor = [UIColor grayColor];
    self.bgSlider.maximumTrackTintColor = [UIColor clearColor];
    self.bgSlider.userInteractionEnabled = YES;
    [self.bottomView addSubview:_bgSlider];
    
    self.slider = [[UISlider alloc] initWithFrame:CGRectMake(180 * SCALEH, 20 * SCALEW, 447 * SCALEH, 20 * SCALEW)];
    self.slider.maximumTrackTintColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.2];
    [self.slider addTarget:self action:@selector(sliderUpAction) forControlEvents:UIControlEventTouchUpInside];
    [self.slider addTarget:self action:@selector(sliderValueChange) forControlEvents:UIControlEventValueChanged];
    [self.bottomView addSubview:self.slider];
    
    self.player = [self player];
    
    self.topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, HEIGHT, 50*SCALEW)];
    self.topView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
    [self.view addSubview:self.topView];
    
    self.backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.backBtn.frame = CGRectMake(0, 0, 60 * SCALEH, 50 * SCALEW);
    [self.backBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [self.backBtn setImage:[UIImage imageNamed:@"btn_nav_back@2x.png"] forState:UIControlStateNormal];
    [self.topView addSubview:self.backBtn];
    
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(70 * SCALEH, 10* SCALEW, 447*SCALEH, 30*SCALEW)];
    self.titleLabel.text = _currentTitle;
    self.titleLabel.font = [UIFont systemFontOfSize:18];
    [self.topView addSubview:self.titleLabel];
    
    self.typeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.typeBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    self.typeBtn.layer.borderWidth = 2;
    self.typeBtn.titleLabel.font = [UIFont systemFontOfSize:15*SCALEH];
    self.typeBtn.frame = CGRectMake(487 * SCALEH, 15 * SCALEW, 70 * SCALEH, 20 * SCALEW);
    self.typeBtn.tag = 101;
    [self.typeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.typeBtn setTitle:@"标清" forState:UIControlStateNormal];
    [self.typeBtn addTarget:self action:@selector(changeType) forControlEvents:UIControlEventTouchUpInside];
    [self.topView addSubview:self.typeBtn];
    
    self.selectedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.selectedBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    self.selectedBtn.layer.borderWidth = 2;
    self.selectedBtn.selected = YES;
    self.selectedBtn.titleLabel.font = [UIFont  systemFontOfSize:15 * SCALEH];
    self.selectedBtn.frame = CGRectMake(597 * SCALEH, 15 *SCALEW, 50 * SCALEH, 20 *SCALEW);
    [self.selectedBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.selectedBtn setTitle:@"选集" forState:UIControlStateNormal];
    [self.selectedBtn addTarget:self action:@selector(selectedAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.topView addSubview:self.selectedBtn];
    
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 50 * SCALEW, HEIGHT, 265*SCALEW)];
    [self.view addSubview:bgView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
    [bgView addGestureRecognizer:tap];
    
    [self initTypeView];
    
}
//初始化 清晰度视图
- (void)initTypeView{
    NSString *highUrl = [[_videoModel.playInfo objectAtIndex:0] objectForKey:@"url"];
    if (highUrl != nil && _videoModel != nil) {
        [self.typeBtn setTitle:@"切换高清" forState:UIControlStateNormal];
    }else{
        self.typeBtn.alpha = 0;
    }
}
- (void)initSelectedTableView{
    if (self.videoModelArray.count != 0) {
        self.selectedTableView = [[UITableView alloc] initWithFrame:CGRectMake(WIDTH, 50 * HEIGHT / 375, 200 * WIDTH / 667, 265 * HEIGHT / 375) style:UITableViewStylePlain];
        NSLog(@"$%f",WIDTH);
        self.selectedTableView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
        self.selectedTableView.dataSource = self;
        self.selectedTableView.delegate = self;
        self.selectedTableView.alpha = 0;
//        self.selectedTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.view addSubview:self.selectedTableView];
    }else{
        self.selectedTableView.alpha = 0;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (_videoModelArray.count == 0) {
        return 2;
    }
    return _videoModelArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    XJCVideoModel *model = [_videoModelArray objectAtIndex:indexPath.row];
    if (model.title != nil) {
        cell.textLabel.text = model.title;
    }
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.textColor = [UIColor whiteColor];
    return cell;
}

//控件用户交互关闭
- (void)userEnable{
    self.selectedBtn.userInteractionEnabled = NO;
    self.playOrPause.userInteractionEnabled = NO;
    self.slider.userInteractionEnabled = NO;
    if (self.selectedTableView != nil) {
        self.selectedBtn.alpha = 0.2;
    }
}
//控件用户交互开启
- (void)userAble{
    self.selectedBtn.userInteractionEnabled = YES;
    self.playOrPause.userInteractionEnabled = YES;
    self.slider.userInteractionEnabled = YES;
    if (self.selectedTableView != nil) {
        self.selectedBtn.alpha = 1;
    }
}

/*******以上为视图初始化事件*******/

/*******以下为交互事件************/

//切换清晰度
- (void)changeType{
    if (self.typeBtn.tag == 101) {
        [self.typeBtn setTitle:@"切换标清" forState:UIControlStateNormal];
        _url = [NSURL URLWithString:_videoModel.playUrl];
        [self removeObserverFromPlayerItem:self.player.currentItem];
        AVPlayerItem *playerItem = [self getPlayItem:self.url];
        [self addObserverToPlayerItem:playerItem];
        //隐藏和关闭控件
        [self userEnable];
        [self hiddenAllViews];
        
        //切换视频
        [self.player replaceCurrentItemWithPlayerItem:playerItem];
        [self.player play];
        self.typeBtn.tag = 102;
        return;
    }
    [self.typeBtn setTitle:@"切换高清" forState:UIControlStateNormal];
    _url = [NSURL URLWithString:_videoModel.playUrl];
    [self removeObserverFromPlayerItem:self.player.currentItem];
    AVPlayerItem *playerItem = [self getPlayItem:self.url];
    [self addObserverToPlayerItem:playerItem];
    
    //隐藏和关闭控件
    [self userEnable];
    [self hiddenAllViews];
    
    //切换视频
    [self.player replaceCurrentItemWithPlayerItem:playerItem];
    [self.player play];
    self.typeBtn.tag = 101;
}

//显示提示框
- (void)showMessage:(NSString *)text{
    self.messageBox.alpha = 1;
    self.messageBox.text = text;
    [self.view bringSubviewToFront:self.messageBox];
}
//隐藏提示框
- (void)hiddenMessageBox{
    self.messageBox.alpha = 0;
}

//隐藏所有控件
- (void)hiddenAllViews{
    [UIView animateWithDuration:0.3 animations:^{
        
        self.topView.alpha = 0;
        self.bottomView.alpha = 0;
        self.selectedTableView.alpha = 0;
    }];
}

//显示所有控件
- (void)showAllViews{
    [UIView animateWithDuration:0.3 animations:^{
        
        self.topView.alpha = 1;
        self.bottomView.alpha = 1;
        self.selectedTableView.alpha = 1;
    }];
}

//tableview点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    XJCVideoModel *model = [_videoModelArray objectAtIndex:indexPath.row];
    NSURL *url = nil;
    if ([model.playUrl rangeOfString:@"http"].location == NSNotFound) {
        url = [NSURL fileURLWithPath:model.playUrl];
    }else{
        url = [NSURL URLWithString:model.playUrl];
    }
    
    if (url == _url) {
        return;
    }
    NSString *text = @"";
    if (model.title != nil) {
        
        text = model.title;
        
    }else{
        
        text = model.playUrl;
    }
    
    _url = url;
    [self removeObserverFromPlayerItem:self.player.currentItem];
    AVPlayerItem *playerItem = [self getPlayItem:_url];
    [self addObserverToPlayerItem:playerItem];
    
    //隐藏和关闭控件
    [self userEnable];
    [self hiddenAllViews];
    
    //切换视频
    [self.player replaceCurrentItemWithPlayerItem:playerItem];
    self.titleLabel.text = text;
    [self.player play];
}

//轻拍屏幕事件
- (void)tapAction{
    if (self.selectedTableView.alpha == 1 && self.bottomView.alpha != 1) {
        [UIView animateWithDuration:0.3 animations:^{
            self.selectedTableView.alpha = 0;
        }];
        return;
    }
    if (self.bottomView.alpha == 0) {
        [UIView animateWithDuration:0.3 animations:^{
            self.bottomView.alpha = 1;
            self.topView.alpha = 1;
            self.hiddenCount = 0;
        }];
    }else{
        [UIView animateWithDuration:0.3 animations:^{
            
            self.topView.alpha = 0;
            self.bottomView.alpha = 0;
            self.hiddenCount = 6;
            self.selectedTableView.alpha = 0;
        }];
    }
}
//播放/暂停事件
- (void)playOrPauseAction{
    if (self.player.rate == 0) {
        //说明是暂停
        [self.playOrPause setImage:[UIImage imageNamed:@"pause@2x"] forState:UIControlStateNormal];
        [self.player play];
        _isPause = NO;
    }else if (self.player.rate == 1){
        //正在播放
        [self.player pause];
        [self.playOrPause setImage:[UIImage imageNamed:@"play@2x"] forState:UIControlStateNormal];
        self.isPause = YES;
    }
}
//slideValue改变事件
- (void)sliderValueChange{
    self.isOperation = YES;
    NSString *text = [self convertTime:self.slider.value];
    [self showMessage:text];
}
//slider推动完成事件
- (void)sliderUpAction{
    NSInteger dragedSeconds = floorf(_slider.value);
    
    //转换成CMTime才能给player来控制播放速度
    CMTime dragedCMTime = CMTimeMake(dragedSeconds, 1);
    
    __weak typeof(self) weakSelf = self;
    
    //隐藏和关闭控件
    [self.player seekToTime:dragedCMTime completionHandler:^(BOOL finished) {
        [weakSelf.player play];
        weakSelf.isOperation = NO;
        [weakSelf hiddenMessageBox];
        
    }];
}
//选集按钮事件
- (void)selectedAction:(UIButton *)sender{
    if (self.selectedBtn.selected) {
        [UIView animateWithDuration:0.3 animations:^{
            
            self.selectedTableView.frame = CGRectMake(467 *(WIDTH / 667), 50 *( HEIGHT / 375), 200 *( WIDTH / 667), 265 *(HEIGHT / 375));
            self.selectedTableView.alpha = 1;
        }];
    }else{
        [UIView animateWithDuration:0.3 animations:^{
            
            self.selectedTableView.frame = CGRectMake(WIDTH, 50 * (HEIGHT / 375), 200 * WIDTH / 667, 265 * HEIGHT / 375);
        }];
        
//        self.selectedTableView.alpha = 0;
    }
    self.selectedBtn.selected =! self.selectedBtn.selected;
}
//返回事件
- (void)backAction{

    [self removeObserverFromPlayerItem:self.player.currentItem];
    [self.player removeTimeObserver:_playBackObserver];
    [self dismissViewControllerAnimated:YES completion:nil];
}
/********以上为交互事件*****/


/********以下为播放器事件****/
/**
 *  初始化播放器
 *
 *  @return 播放器对象
 */
- (AVPlayer *)player{
    
    if (!_player) {
        AVPlayerItem *playerItem = [self getPlayItem:self.url];
        _player = [AVPlayer playerWithPlayerItem:playerItem];
        [self addObserverToPlayerItem:playerItem];
    }
    return _player;
}
/**
 *  根据视频索引取得AVPlayerItem对象
 *
 *  @param videoIndex 视频顺序索引
 *
 *  @return AVPlayerItem对象
 */

- (AVPlayerItem *)getPlayItem:(NSURL *)url{
    AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url];
    return playerItem;
}
/**
 *  初始化子控件
 */
- (void)setupSubviews{
    //创建播放器层
    AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
    playerLayer.frame = self.container.frame;
    [self.container.layer addSublayer:playerLayer];
}
- (void)setVideoModel:(XJCVideoModel *)videoModel{
    _videoModel = videoModel;
    
    if ([videoModel.playUrl rangeOfString:@"http"].location == NSNotFound) {
        
        _url = [NSURL fileURLWithPath:videoModel.playUrl];
        _currentTitle = videoModel.title;
        return;
    }

    _url = [NSURL URLWithString:videoModel.playUrl];
    _currentTitle = videoModel.title;
}

/**
 *  给AVPlayerItem添加监控
 *
 *  @param playerItem AVPlayerItem对象
 */
- (void)addObserverToPlayerItem:(AVPlayerItem *)playerItem{
    
    //监听状态属性,注意AVPlayer也有一个status属性,通过监控它的statu也可以获得播放状态
    [playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];
    //监控网络加载情况属性
    [playerItem addObserver:self forKeyPath:@"loadedTimeRanges" options:NSKeyValueObservingOptionNew context:nil];
    
}
/**
 *  通过KVO监控播放器状态
 *
 *  @param keyPath 监控属性
 *  @param object  监视器
 *  @param change  状态改变
 *  @param context 上下文
 */
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context{
    AVPlayerItem *playerItem = object;
    if ([keyPath isEqualToString:@"status"]) {
        AVPlayerStatus status = [[change objectForKey:@"new"]intValue];
        if (status == AVPlayerStatusReadyToPlay) {
            NSLog(@"正在播放--- 视频总长度:%.2f",CMTimeGetSeconds(playerItem.duration));
            //视频总长度
            CMTime duration = playerItem.duration;
            self.slider.maximumValue = CMTimeGetSeconds(duration);
            self.bgSlider.maximumValue = CMTimeGetSeconds(duration);
            //监听播放状态
            [self addProgressObserver];
            [self userAble];
        }
    }else if ([keyPath isEqualToString:@"loadedTimeRanges"]){
        
        NSArray *array = playerItem.loadedTimeRanges;
        //本次缓冲的时间范围
        CMTimeRange timeRange = [array.firstObject CMTimeRangeValue];
        float startSeconds = CMTimeGetSeconds(timeRange.start);
        float durationSeconds = CMTimeGetSeconds(timeRange.duration);
        //缓冲总长度
        NSTimeInterval totalBuffer = startSeconds + durationSeconds;
        _bgSlider.value = totalBuffer;
        
        CGFloat currentTime = CMTimeGetSeconds(_player.currentTime) + 5;
        
        if (totalBuffer >= currentTime && _isPause == NO && _player.rate == 0) {
            [_player play];
//            _isPause = YES;
        }
        
        NSLog(@"共缓冲:%.2f--播放时间%f",totalBuffer, CMTimeGetSeconds(_player.currentTime));
    }
}

/**
 *移除监控
 */
- (void)removeObserverFromPlayerItem:(AVPlayerItem *)playerItem{
    [playerItem removeObserver:self forKeyPath:@"status"];
    [playerItem removeObserver:self forKeyPath:@"loadedTimeRanges"];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    NSLog(@"item = %@",_player);
}

#pragma mark -- 监控 
/**
 *给播放器添加进度更新
 */
- (void)addProgressObserver{
    AVPlayerItem *playerItem = _player.currentItem;
    __weak typeof(self) weakself = self;
    if (_playBackObserver != nil) {
        [self.player removeTimeObserver:_playBackObserver];
    }
    //设置每秒执行一次
    _playBackObserver = [_player addPeriodicTimeObserverForInterval:CMTimeMake(1.0, 1.0) queue:dispatch_get_main_queue() usingBlock:^(CMTime time) {
        CGFloat current = CMTimeGetSeconds(time);
        CGFloat total = CMTimeGetSeconds([playerItem duration]);
        NSString *currentStr = [weakself convertTime:current];
        NSString *totalStr = [weakself convertTime:total];
        weakself.timeLabel.text = [NSString stringWithFormat:@"%@/%@",currentStr,totalStr];
        NSLog(@"当前播放时间%f--总时间%f",current,total);
        if (weakself.isOperation == NO) {
            if (weakself.hiddenCount <= 8 ) {
                if (weakself.hiddenCount == 8) {
                    [weakself hiddenAllViews];
                }
                weakself.hiddenCount++;
            }
            [weakself.slider setValue:current animated:YES];
        }
        
    }];
}

//时间转换
- (NSString *)convertTime:(CGFloat)second{
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:second];
    if (second / 3600 >= 1) {
        [[self dateFormatter] setDateFormat:@"HH:mm:ss"];
    }else{
        [[self dateFormatter] setDateFormat:@"mm:ss"];
    }
    NSString *showTimeNew = [[self dateFormatter] stringFromDate:date];
    return showTimeNew;
}
- (NSDateFormatter *)dateFormatter{
    if (!_dateFormatter) {
        _dateFormatter = [[NSDateFormatter alloc] init];
    }
    return _dateFormatter;
}

/****强制横屏****/
- (BOOL)shouldAutorotate{
    [self initSelectedTableView];

    return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationLandscapeRight;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscapeRight;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
